# Maintainer: Noel Kuntze <noel.kuntze@contauro.com>
pkgname=grommunio-common
pkgver=1.0
pkgrel=2
pkgdesc="Common configuration package for grommunio"
arch="noarch !riscv64"
url="https://grommunio.com/"
license="AGPL-3.0-only"
options="!check" # No test suite
subpackages="$pkgname-openrc"

source="$pkgname-$pkgver.tar.gz::https://github.com/grommunio/configs/archive/refs/tags/v$pkgver.tar.gz
	0001-valkey-grommunio.patch
	0002-nginx-http2.patch

	ssl_certificate.conf
	valkey@grommunio.initd
	valkey@grommunio.confd
	"

builddir="$srcdir/configs-$pkgver"

package() {
	mkdir -p "$pkgdir"
	cp -rp -- * "$pkgdir"

	# service files
	install -dm755 "$pkgdir"/etc/init.d/
	ln -sf "/etc/init.d/valkey" "$pkgdir/etc/init.d/valkey@grommunio"
	install -Dm644 "$srcdir"/valkey@grommunio.confd "$pkgdir"/etc/conf.d/valkey@grommunio

	# fix redis directory
	mv "$pkgdir/etc/redis" "$pkgdir/etc/valkey"

	# fix nginx directory
	mv "$pkgdir/etc/nginx/conf.d" "$pkgdir/etc/nginx/http.d"

	# nginx config file
	install -m644 -D "$srcdir"/ssl_certificate.conf "$pkgdir"/etc/grommunio-common/nginx/ssl_certificate.conf

	# remove unnecessary directories
	rm -r "$pkgdir"/var/lib "$pkgdir"/var/log \
		"$pkgdir"/etc/grommunio-common/nginx/locations.d \
		"$pkgdir"/etc/grommunio-common/nginx/upstreams.d
}

sha512sums="
1e2db173a73012948be3b829919ab3092ba0399228355d7a157398bb5b4b9d6c4150b1f2aaf38cfb857dba710765408a54cf2aab09e369c28d1971a29f221b26  grommunio-common-1.0.tar.gz
6ce31c164c833950f482bf1d02200d52b1e8c91d28be2271d5b722eaa1f84e9c574a2d6ab5da47d728e8005d9762474ac0fbcd292d39bba4a451593a27a8cf97  0001-valkey-grommunio.patch
095b32d8e832bfbaae78092269b3312b79492f237a47971e1ed3c1d4ab486c2f09b83aca788a5c24e8d39fc18552e3085973a783666be956cdfaaf8d33b1f1b1  0002-nginx-http2.patch
e2d1a010813078651ca2e728589a1c0c84b6e098c87f59b2ec07d54a9f80b8c9a2168cd853dd73fe07ee6e05cc66f762c2d9ba2511c135314bb1727f6cbfba91  ssl_certificate.conf
192ed1b71c933c750920cf40eb1e277c5f874fc0f87402a3b9696717fc388bb62153a6e0f759c148b510975bc1cc1b84ef06b2df8b7067ebbed33caeb784e383  valkey@grommunio.initd
5d2bb73c96e9455c6a78ec008820b6dda43776f3911f7104f2075fea64ec77434c26eb92ab481c8b325f22b96f60d5ef6685b41fa3ddf5857ffed5ecdd142100  valkey@grommunio.confd
"
